<template>
  <div class="loading">
    <div class="box">
      <div class="box-loading">
        <div class="lod">
          <img src="../assets/logo.png" alt="" />
        </div>
      </div>
      <el-form
        status-icon
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="用户名" prop="pass">
          <el-input
            type="text"
            v-model="name"
            autocomplete="off"
            @blur="ts1"
          ></el-input>
          <div class="ts" v-show="show1">用户名不能为空</div>
        </el-form-item>
        <el-form-item label="密码" prop="pass">
          <el-input
            type="password"
            v-model="pass"
            autocomplete="off"
            @blur="ts2"
          ></el-input>
          <div class="ts" v-show="show2">密码不能为空</div>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="loagin">提交</el-button>
          <el-button class="cz" @click="nul">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      name: "",
      pass: "",
      show1: false,
      show2: false,
    };
  },
  methods: {
    loagin() {
      this.$http
        .post("/login", { username: this.name, password: this.pass })
        .then((res) => {
          console.log(res);
          if (res.meta.status == 200) {
            localStorage.setItem("token", res.data.token);
            this.$router.push("/heade");
            this.$message({
              message: res.meta.msg,
              type: "success",
            });
          } else {
            this.$message({
              message: res.meta.msg,
              type: "error",
            });
          }
        });
    },
    //login用户密码的判断
    ts1() {
      if (this.name == "") {
        this.show1 = true;
      }
    },
    ts2() {
      if (this.pass == "") {
        this.show2 = true;
      }
    },
    //错误提示判空框
    nul() {
      this.name = "";
      this.pass = "";
    },
  },
  mounted() {},
  watch: {
    name() {
      this.show1 = false;
    },
    pass() {
      this.show2 = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.loading {
  width: 100%;
  height: 100vh;
  background: rgb(43, 75, 107);
  position: relative;
}
.box {
  width: 500px;
  height: 300px;
  background: rgb(255, 255, 255);
  // margin: 0 auto;
  position: absolute;
  top: 200px;
  left: 500px;
  border-radius: 10px 10px 10px 10px;
}
.box-loading {
  width: 100%;
  height: 30%;
  //   background: rgb(209, 211, 208);
  margin-bottom: 20px;
  border-radius: 10px 10px 0px 0px;
}
::v-deep .el-input__inner {
  -webkit-appearance: none;
  background-color: #fff;
  background-image: none;
  border-radius: 4px;
  border: 1px solid #dcdfe6;
  box-sizing: border-box;
  color: #606266;
  display: inline-block;
  font-size: inherit;
  height: 40px;
  line-height: 40px;
  outline: 0;
  padding: 0 15px;
  transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  width: 80%;
}
::v-deep .el-form demo-ruleForm {
  margin-top: 10px;
}
::v-deep .el-button {
  display: inline-block;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  background: rgb(2, 137, 255);
  border: 1px solid #dcdfe6;
  color: #606266;
  -webkit-appearance: none;
  text-align: center;
  box-sizing: border-box;
  outline: 0;
  margin: 0;
  transition: 0.1s;
  font-weight: 500;
  padding: 12px 20px;
  font-size: 14px;
  border-radius: 4px;
  margin-left: 170px;
}
.cz {
  background: hsl(0, 4%, 78%);
}
.lod {
  width: 150px;
  height: 150px;
  background: rgb(255, 255, 255);
  position: relative;
  top: -75px;
  left: 180px;
  border-radius: 100px 100px 100px 100px;
  box-shadow: 1px -1px 10px 0px rgb(255, 255, 255);
  img {
    width: 80%;
    height: 80%;
    margin-top: 16px;
    margin-left: 16px;
    background: rgb(238, 238, 238);
    border-radius: 100px 100px 100px 100px;
  }
}
.ts {
  font-size: 12px;
  height: 5px;
  color: red;
}
.cz[data-v-7589b93f] {
  background: #c9c5c5;
  position: absolute;
  left: 85px;
}
</style>
